package com.wze.wze.Controller;

import com.wze.wze.Aop.PasToken;
import com.wze.wze.Entity.Music;
import com.wze.wze.Entity.ResultEntity;
import com.wze.wze.Entity.v_music;
import com.wze.wze.Entity.v_mv;
import com.wze.wze.Service.v_musicService;
import com.wze.wze.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域
@RestController //控制器注解
@RequestMapping("/vMusic/")//请求路径
public class v_musicController {
    @Resource
    v_musicService v_musicService;
    ResultEntity resultEntity = null;


    @GetMapping("Music")
    private String getMusicById(@RequestParam("id") int id) {
        resultEntity = new ResultEntity();
        try {
            v_music music  = v_musicService.getMusicById(id);
            if (music == null) {
                resultEntity.setCode("1");
                resultEntity.setMsg("查无此音乐");
            } else {
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setData(music);
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultEntity.setCode("9999");
            resultEntity.setMsg("系统错误，请联系管理员");
        }
        return JSONTool.getJsonTool().toJson(resultEntity);

    }

    @PasToken
    @GetMapping("mvUnList")
    private String PlList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("id")  int id,
            @RequestParam("Sid")  int Sid
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_music> list = v_musicService.getUnMusicList(Start, limit, id,Sid);
            if(id!=-1 || Sid!=-1){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(v_musicService.getMusicCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }
    @PasToken
    @GetMapping("mvList")
    private String PlUnList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("id")  int id,
            @RequestParam("MusicName")  String MusicName
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_music> list = v_musicService.getMusicList(Start, limit, id,MusicName);
            if(id!=-1 || !MusicName.equals("")){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(v_musicService.getMusicCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }
}
